package com.xp.agent.task;

import com.xp.agent.common.Item;
import com.xp.agent.common.MessageQueue;
import com.xp.agent.dto.AlarmMessage;
import com.xp.agent.dto.ConfigDto;
import com.xp.agent.service.ThreadCountService;
import com.xp.hotswap.builder.ApplicationContext;

public class ThreadTask implements Runnable {

	@Override
	public void run() {
		while (true) {
			try {
				ThreadCountService beans = (ThreadCountService) ApplicationContext.getBeans(ThreadCountService.class);
				long collect = beans.collect();
				long threshold = ConfigDto.instance.getPro(Item.ThreadCount.getItemName());
				if (collect >= threshold) {
					AlarmMessage message = new AlarmMessage(Item.ThreadCount.getItemName(), System.currentTimeMillis(),
							collect, threshold);
					MessageQueue.getInstance().put(message);
				}
				beans = null;
				Thread.sleep(ConfigDto.instance.getPro(Item.ThreadTime.getItemName()));
			} catch (Throwable t) {
			}
		}
	}

}
